import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;
class Index {
    int x;
    int y;
    int level;
    public Index(int x, int y, int level) {
        this.x = x;
        this.y = y;
        this.level = level;
    }
}
public class Day42 {
    static final int N = 10;

    // 思路：采用广度优先遍历，找到即为最短
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            // 构造地图
            char[][] map = new char[N][N];
            for (int i = 0; i < N; i ++) {
                map[i] = in.nextLine().toCharArray();
            }
            // bfs 搜索
            int res = bfs(map, 0, 1, N, N);
            System.out.println(res);
            // 测试地图输入是否成功
//#.########
//#........#
//#........#
//#........#
//#........#
//#........#
//#........#
//#........#
//#........#
//########.#
//            for (int i = 0; i < N; i++) {
//                for (int j = 0; j < 10; j++) {
//                    System.out.print(map[i][j] + " ");
//                }
//                System.out.println();
//            }
        }
    }

    private static int bfs(char[][] map, int x, int y, int row, int col) {
        // 定义上下左右四个搜索方向
        int[][] directs = {{-1,0},{0,1},{1,0},{0,-1}};
        // 计数
        int count = 0;
        // 广度搜索
        Deque<Index> queue = new LinkedList<>();
        Index start = new Index(x,y,0);
        queue.offer(start);
        map[x][y] = '#';
        while (!queue.isEmpty()) {
            Index index = queue.poll();
            if (index.x == 9 && index.y == 8) return index.level;
            for (int i = 0; i < 4; i++) {
                int nx = index.x + directs[i][0];
                int ny = index.y + directs[i][1];
                if (nx >= 0 && nx < row && ny >= 0 && ny < col && map[nx][ny] != '#') {
                    queue.offer(new Index(nx,ny, index.level+1));
                    // 标记为已走过
                    map[nx][ny] = '#';
                }
            }
        }
        return 0;
    }
}
